<div class="popup_body">
    <div class="ui_table">
        <form method="post">
            <input type="hidden" name="basePriceId">
            <input type="hidden" name="activityPriceId">
            <table cellpadding="0" cellspacing="0">

                <tr>
                    <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                        <td align="right">运营商：</td>
                        <td>
                            <input name="agentId" class="easyui-combotree" editable="false" required="true"
                                   style="width: 184px; height: 28px;" id="agent_id_${pid}"
                                   data-options="url:'${contextPath}/security/basic/agent/tree.htm?',method:'get',onSelect: function(rec){
                                   var url = '${contextPath}/security/hdw/agency/tree.htm?agentId='+rec.id;
                                   $('#agency_id_${pid}').combotree('reload', url);},
                                   onChange:function(){
                                    $('#agency_id_${pid}').combotree('clear');
                                    }
                                    "/>
                        </td>
                    </#if>
                </tr>
                <tr>
                    <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value>
                        <td align="right">代理商：</td>
                        <td>
                            <input name="agencyId" class="easyui-combotree" editable="false"
                                   style="width: 184px; height: 28px;" id="agency_id_${pid}"
                                   data-options="<#if Session['SESSION_KEY_USER'].agentId??&&Session['SESSION_KEY_USER'].agentId!=0>url:'${contextPath}/security/hdw/agency/tree.htm?agentId=${Session['SESSION_KEY_USER'].agentId}',</#if>method:'get'"/>
                        </td>
                    </#if>

                </tr>
                <tr>
                    <td width="80px;" align="right">套餐名称：</td>
                    <td><input type="text" class="text easyui-validatebox"required="required" maxlength="40" name="settingName" /></td>
                </tr>
                <tr>

                    <td align="right">日常套餐：</td>
                    <td><input type="text" class="text easyui-validatebox" required="required" maxlength="40" name="basePriceName" /></td>
                </tr>
                <tr>
                    <td align="right">活动套餐：</td>
                    <td><input type="text" class="text easyui-validatebox" maxlength="40" name="activityPriceName"/></td>
                </tr>
                <tr>

                    <td align="right">开始时间：</td>
                    <td><input type="text" class="text easyui-datetimebox" style="width:185px;height:28px " id="begin_time_${pid}" name="activityBeginTime" ></td>
                </tr>
                    <td align="right">结束时间：</td>
                    <td><input type="text" class="text easyui-datetimebox" style="width:185px;height:28px " id="end_time_${pid}" name="activityEndTime"></td>

            </table>
        </form>
    </div>
</div>
<div class="popup_btn">
    <button class="btn btn_red ok">确定</button>
    <button class="btn btn_border close">关闭</button>
</div>
<script>
    (function() {
        var pid = '${pid}',
                win = $('#' + pid),
                form = win.find('form');

        win.find('input[name=basePriceId],input[name=basePriceName]').click(function() {
            <#--新增权限判断：不同权限登录查询属于自己的套餐-->
            if(${Session['SESSION_KEY_USER'].type} == ${Session['USER_TYPE_AGENT'].value}) {
                <#--这句可以不加-->
                if ($('#agent_id_${pid}').length > 0) {
                    var agentId = $('#agent_id_${pid}').combotree('getValue');

                }
                if ($('#agency_id_${pid}').length > 0) {
                    var agencyId = $('#agency_id_${pid}').combotree('getValue');
                }
                <#--因为是运营商登录，所以在没有运营商输入栏时要给其赋值，否则链接跳转时提示 agentId 为未定义-->
                agentId=${Session['SESSION_KEY_USER'].agentId};

                selectBasePrice(agentId, agencyId);

            }

            if(${Session['SESSION_KEY_USER'].type} == ${Session['USER_TYPE_AGENCY'].value}) {
                <#--这两句可以不加-->
                if ($('#agent_id_${pid}').length > 0) {
                    var agentId = $('#agent_id_${pid}').combotree('getValue');

                }
                if ($('#agency_id_${pid}').length > 0) {
                    var agencyId = $('#agency_id_${pid}').combotree('getValue');
                }
                agentId=${Session['SESSION_KEY_USER'].agentId};
                agencyId=${Session['SESSION_KEY_USER'].agencyId};

                selectBasePrice(agentId, agencyId);

            }
            if(${Session['SESSION_KEY_USER'].type} == ${Session['USER_TYPE_PLATFORM'].value}){
                var agentId = $('#agent_id_${pid}').combotree('getValue');
                var agencyId= $('#agency_id_${pid}').combotree('getValue');
                <#--还是要判断空字符串的-->
                if (agentId == null || agentId=='') {
                    $.messager.alert('提示信息', '请选择运营商', 'info');

                }
                else if (agencyId == null || agencyId=='') {
                    //agencyId=null;
                    selectBasePrice(agentId, agencyId);
                } else {

                    selectBasePrice(agentId, agencyId);
                }
            }


        });

        function selectBasePrice(agentId,agencyId) {
            App.dialog.show({
                css: 'width:826px;height:522px;overflow:visible;',
                title: '选择基础套餐',
                href: '${contextPath}/security/hdw/exchange_price/select_base_price.htm?agentId=' + agentId + '&agencyId=' +agencyId,
                windowData: {
                    ok: function(config) {
                        win.find('input[name=basePriceId]').val(config.exchargerPrice.id);
                        win.find('input[name=basePriceName]').val(config.exchargerPrice.priceName);
                    }
                },
                event: {
                    onClose: function() {
                    }
                }
            });
        }
        win.find('input[name=activityPriceId],input[name=activityPriceName]').click(function() {
        <#--新增权限判断：不同权限登录查询属于自己的套餐-->
            if(${Session['SESSION_KEY_USER'].type} == ${Session['USER_TYPE_AGENT'].value}) {
            <#--这句可以不加-->
                if ($('#agent_id_${pid}').length > 0) {
                    var agentId = $('#agent_id_${pid}').combotree('getValue');

                }
                if ($('#agency_id_${pid}').length > 0) {
                    var agencyId = $('#agency_id_${pid}').combotree('getValue');
                }
            <#--因为是运营商登录，所以在没有运营商输入栏时要给其赋值，否则链接跳转时提示 agentId 为未定义-->
                agentId=${Session['SESSION_KEY_USER'].agentId};

                selectActivityPrice(agentId, agencyId);

            }

            if(${Session['SESSION_KEY_USER'].type} == ${Session['USER_TYPE_AGENCY'].value}) {
            <#--这两句可以不加-->
                if ($('#agent_id_${pid}').length > 0) {
                    var agentId = $('#agent_id_${pid}').combotree('getValue');

                }
                if ($('#agency_id_${pid}').length > 0) {
                    var agencyId = $('#agency_id_${pid}').combotree('getValue');
                }
                agentId=${Session['SESSION_KEY_USER'].agentId};
                agencyId=${Session['SESSION_KEY_USER'].agencyId};

                selectActivityPrice(agentId, agencyId);

            }
            if(${Session['SESSION_KEY_USER'].type} == ${Session['USER_TYPE_PLATFORM'].value}){
                var agentId = $('#agent_id_${pid}').combotree('getValue');
                var agencyId= $('#agency_id_${pid}').combotree('getValue');
            <#--还是要判断空字符串的-->
                if (agentId == null || agentId=='') {
                    $.messager.alert('提示信息', '请选择运营商', 'info');

                }
                else if (agencyId == null || agencyId=='') {
                    //agencyId=null;
                    selectActivityPrice(agentId, agencyId);
                } else {

                    selectActivityPrice(agentId, agencyId);
                }
            }
        });

        function selectActivityPrice(agentId,agencyId) {
            App.dialog.show({
                css: 'width:826px;height:522px;overflow:visible;',
                title: '选择基础套餐',
                href: '${contextPath}/security/hdw/exchange_price/select_activity_price.htm?agentId=' + agentId + '&agencyId='+agencyId ,
                windowData: {
                    ok: function(config) {
                        win.find('input[name=activityPriceId]').val(config.exchargerPrice.id);
                        win.find('input[name=activityPriceName]').val(config.exchargerPrice.priceName);
                    }
                },
                event: {
                    onClose: function() {
                    }
                }
            });
        }
        win.find('button.ok').click(function() {
            form.form('submit', {
                url: '${contextPath}/security/hdw/exchange_price_setting/create.htm',
                onSubmit: function(param) {

                    var beginTime = $('#begin_time_${pid}').datetimebox('getValue');
                    var endTime = $('#end_time_${pid}').datetimebox('getValue');
                    if(beginTime != '' && endTime != '' && beginTime > endTime) {
                        $.messager.alert('提示信息', '结束时间必须大于开始时间', 'info');
                        return;
                    }
                    //表单校验
                    if(!form.form('validate')){
                        return false;
                    }
                    return true;
                },
                success: function(text) {
                    var json = $.evalJSON(text);
                <@app.json_jump/>
                    if(json.success) {
                        $.messager.alert('提示信息', '操作成功', 'info');
                        win.window('close');
                    } else {
                        $.messager.alert('提示信息', json.message, 'info');
                    }
                }
            });
        });

        win.find('button.close').click(function() {
            win.window('close');
        });
    })()
</script>
